Learn R Programming

bnlearn (version 3.8.1)

arc operations: Drop, add or set the direction of an arc or an edge

Description

Drop, add or set the direction of an arc or an edge.

Usage

# arc operations.
set.arc(x, from, to, check.cycles = TRUE, debug = FALSE)
drop.arc(x, from, to, debug = FALSE)
reverse.arc(x, from, to, check.cycles = TRUE, debug = FALSE)

# edge (i.e. undirected arc) operations set.edge(x, from, to, check.cycles = TRUE, debug = FALSE) drop.edge(x, from, to, debug = FALSE)

Arguments

x
an object of class bn.
from
a character string, the label of a node.
to
a character string, the label of another node.
check.cycles
a boolean value. If TRUE the graph is tested for acyclicity; otherwise the graph is returned anyway.
debug
a boolean value. If TRUE a lot of debugging output is printed; otherwise the function is completely silent.

Value

  • All functions return invisibly an updated copy of x.

Details

The set.arc function operates in the following way:
  • if there is no arc betweenfromandto, the arcfrom$\rightarrow$tois added.
  • if there is an undirected arc betweenfromandto, its direction is set tofrom$\rightarrow$to.
  • if the arcto$\rightarrow$fromis present, it is reversed.
  • if the arcfrom$\rightarrow$tois present, no action is taken.

The drop.arc function operates in the following way:

  • if there is no arc betweenfromandto, no action is taken.
  • if there is a directed or an undirected arc betweenfromandto, it is dropped regardless of its direction.

The reverse.arc function operates in the following way:

  • if there is no arc betweenfromandto, it returns an error.
  • if there is an undirected arc betweenfromandto, it returns an error.
  • if the arcto$\rightarrow$fromis present, it is reversed.
  • if the arcfrom$\rightarrow$tois present, it is reversed.

The set.edge function operates in the following way:

  • if there is no arc betweenfromandto, the undirected arcfrom-tois added.
  • if there is an undirected arc betweenfromandto, no action is taken.
  • if either the arcfrom$\rightarrow$toor the arcto$\rightarrow$fromare present, they are replaced with the undirected arcfrom-to.

The drop.edge function operates in the following way:

  • if there is no undirected arc betweenfromandto, no action is taken.
  • if there is an undirected arc betweenfromandto, it is removed.
  • if there is a directed arc betweenfromandto, no action is taken.

Examples

Run this code
data(learning.test)
res = gs(learning.test)

## use debug = TRUE to get more information.
set.arc(res, "A", "B")
drop.arc(res, "A", "B")
drop.edge(res, "A", "B")
reverse.arc(res, "A", "D")

Run the code above in your browser using DataLab